﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using WebUI.constant;

namespace WebUI.Units
{
    /// <summary>
    /// 数据处理类
    /// </summary>
    public static class DataProcess
    {
        
        //解决Self loop问题
       public static String Obj2Json(Object obj)
        {

            JsonSerializerSettings setting = new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                Formatting = Formatting.None
            };
            var ret = JsonConvert.SerializeObject(obj, setting);
            return ret;
        }

        public static object Json2Obj(String jsonStr,Type type)
        {

            return JsonConvert.DeserializeObject(jsonStr,type);
        }
        /// <summary>
        /// 邮箱正则表达式
        /// </summary>
        /// <returns></returns>
        public static bool EmailRegexCheck(String email)
        {
            Regex rgx = new Regex(Constant.EmailReg);
            return rgx.IsMatch(email);
        }
        /// <summary>
        /// 密码正则表达式
        /// </summary>
        /// <param name="name"></param>
        public static bool PaswordRegexCheck(String psw)
        {
            Regex rgx = new Regex(Constant.Password);
            return rgx.IsMatch(psw);
        }
    }



}